<%@ Page Language="vb" AutoEventWireup="false" Codebehind="AQAddDialog.aspx.vb" Inherits="MIMS_WRS.Web.AQAddDialog" %>
<%@ Register TagPrefix="uc1" TagName="JSCalendarSetup" Src="../UserControls/JSCalendarSetup.ascx" %>
<%@ Register TagPrefix="uc1" TagName="DateTimePicker" Src="../UserControls/DateTimePicker.ascx" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
	<head>
		<title>Add Adjusted Quantity Dialog</title>
		<LINK href="detail.css" type="text/css" rel="stylesheet" name="Default stylesheet">
		<LINK href="common.css" type="text/css" rel="stylesheet" name="Default stylesheet">
		<script language="javascript">
			
			function validateBeforeSubmit() {			
				var tblResult = window.document.getElementById('tblResult');
				var found = false;
				var tbody;
				var selectedRow;
				if (tblResult != null) {			
					tbody = tblResult.getElementsByTagName("TBODY");
					tbody = tbody[0];			
					for (i=0; i<tbody.rows.length; i++) {
						if (tbody.rows[i].cells[0].childNodes[0].checked) {
							found = true;
							selectedRow = tbody.rows[i];
							break;
						}
					}
				}			
				if (found == false) {
					alert('Please select an order');
					return;
				}		
							
				var txtAmount = window.document.getElementById('txtAmount');
				var qty = parseInt(txtAmount.value, 10);
				if (isNaN(qty)) {
					alert('Please enter adjusted quantity');
					txtAmount.focus();
					return;
				} 				
				
				var selSign = window.document.getElementById('selSign');							
				if (selSign.options[selSign.selectedIndex].value == "-")
					qty = -qty;				
				var txtComment = window.document.getElementById('txtComment');
				var returnObj = new Object();
				returnObj.Amount = qty;
				returnObj.Comment = txtComment.value;
				returnObj.POID = selectedRow.cells[0].childNodes[1].value;				
				window.returnValue = returnObj;
				window.close();			
			}
			
			</script>
			<script src="../js/common.js"></script>
			<style>
				DIV#searchPanel { PADDING-RIGHT: 5px; PADDING-LEFT: 5px; FONT-SIZE: 10px; PADDING-BOTTOM: 5px; PADDING-TOP: 5px; BORDER-BOTTOM: black 1px; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; BACKGROUND-COLOR: lightyellow }
				DIV#bottomPanel { PADDING-RIGHT: 5px; PADDING-LEFT: 5px; FONT-SIZE: 10px; PADDING-BOTTOM: 5px; PADDING-TOP: 5px; BORDER-BOTTOM: black 1px; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; BACKGROUND-COLOR: lightyellow }
				</style>
	</head>
	<body scroll="no">
		<form id="Form1" method="post" runat="server">
		<uc1:JSCalendarSetup id="JSCalendarSetup1" runat="server"></uc1:JSCalendarSetup>
			<div id="searchPanel">
				<span>Enter information to search for an order</span>
				<table class="FormTable">
					<tr>
						<td class="Label">Order number:</td>
						<td>
							<asp:TextBox id="txtOrderNo" onkeypress="NumberOnly(0)" runat="server" MaxLength="3" Columns="5"></asp:TextBox></td>
						<td class="Label">Order date:</td>
						<td><uc1:DateTimePicker id="calOrderDate" runat="server" EnableRequiredValidator="false"></uc1:DateTimePicker></td>
					</tr>
					<tr>
						<td class="Label">
							Office:</td>
						<td>
							<asp:DropDownList id="ddlOffice" runat="server"></asp:DropDownList></td>
						<td class="Label"></td>
						<td></td>
					</tr>
					<tr>
						<td colspan="4"><asp:Button Runat="server" ID="btnSearch" Text="search" CssClass="Button L1"></asp:Button></td>
					</tr>
				</table>
			</div>
			<div id="searchResult" style="OVERFLOW: auto; WIDTH: 100%; HEIGHT: 300px">
				<asp:Repeater Runat="server" ID="rptResult">
					<HeaderTemplate>
						<table class="FormTable" width="100%" id="tblResult">
							<thead>
								<th>
								</th>
								<th>
									Office</th><th>Supplier Code</th><th>Order No</th><th>Order Date</th><th>Customer</th>
							</thead>
							<tbody>
					</HeaderTemplate>
					<ItemTemplate>
						<tr>
							<td><input type="radio" id="radSelect" name="radSelect" value='<%# DataBinder.Eval(Container.DataItem, "OfficeID")%>'><input type=hidden id=hidPOID value='<%# DataBinder.Eval(Container.DataItem, "ID")%>'></td>
							<td><%# DataBinder.Eval(Container.DataItem, "OfficeName")%></td>
							<td><%# Convert.ToString(DataBinder.Eval(Container.DataItem, "PONo_Supplier")).PadLeft(3, "0"c) %></td>							
							<td><%# Convert.ToString(DataBinder.Eval(Container.DataItem, "PONo_Number")).PadLeft(3, "0"c) %></td>
							<td><%# Convert.ToDateTime(DataBinder.Eval(Container.DataItem, "OrderDate")).ToShortDateString()%></td>
							<td><%# DataBinder.Eval(Container.DataItem, "CustomerOrLocation")%></td>
						</tr>
					</ItemTemplate>
					<FooterTemplate>
						</tbody> </table>
					</FooterTemplate>
				</asp:Repeater>
			</div>
			<div id="bottomPanel">
				<span>Then enter quantity and issued date</span>
				<table class="FormTable" width="100%">
					<tr>
						<td class="Label" nowrap><span class="Required">*</span>
							Adjusted Quantity:</td>
						<td>
							<select id="selSign"><option value="+">+</option><option value="-">-</option></select><input type="text" id="txtAmount" onkeypress="NumberOnly(0)" MaxLength="9" size="10" />
						</td>						
					</tr>
					<tr>
						<td class="Label">Comment:</td>
						<td><textarea  id="txtComment"  cols="30" Rows="4"></textarea></td>			
					</tr>
					<tr>
						<td colspan="2" align="center" height="40"><input type="button" onclick="validateBeforeSubmit()" ID="btnOK" value="OK" Class="Button L1">&nbsp;<input type="button" onclick="window.close();" value="Cancel" class="Button L1"></td>
					</tr>
				</table>
			</div>						
		</form>
	</body>
	
</html>
